<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
$intID = (int)$_data["ID"];
$strSQL = "select * from `bet_Lotto` where ID = ".$intID;
if(!$RS = @PMA_mysql_query($strSQL, $$_Conn)){
	$GLOBALS["errormessage"] = "Find Lotto Data Error!!";
	ErrMsgOutputHTML("Error", "", 1);
}

if(PMA_mysql_num_rows($RS) == 0){
	@mysql_close($$_Conn);
	header("Location: ".basename($_SERVER["PHP_SELF"])."?op=List");
	exit();
}else{
	$objLotto = PMA_mysql_fetch_object($RS);
}

if(!$_arrPermitChRate[$objLotto -> LType]){
	header("Location: ".basename($_SERVER["PHP_SELF"])."?op=List");
	exit();
}

//找出 Lotto 的賠率兌換，傳回陣列
$arrORate = getArrayLottoChRateData($intID);
if($arrORate === false)ErrMsgOutputHTML("Error", "", 1);

$arrBT = array();
$arrBTComm = array();
$strSQL =  "select ID as BID, Type_Value_".$_intLang." as Type_Value, A_Commission_MinValue, B_Commission_MinValue, C_Commission_MinValue from `bet_BetType` where LType = '".$objLotto -> LType."' order by ID";
if($subRS = @PMA_mysql_query($strSQL, $$_Conn)){
	if(PMA_mysql_num_rows($subRS) > 0){
		while($subRows = PMA_mysql_fetch_object($subRS)){
			$arrBT[$subRows -> BID] = $subRows -> Type_Value;
			$arrBTComm[$subRows -> BID][1] = $subRows -> A_Commission_MinValue;
			$arrBTComm[$subRows -> BID][2] = $subRows -> B_Commission_MinValue;
			$arrBTComm[$subRows -> BID][3] = $subRows -> C_Commission_MinValue;
		}
	}
}

$fp = @file($strTemplatePath."ChRate.html");
$fp = implode("", $fp);
$fp = setHTMLCharset($fp);

$fp = str_replace("{intID}", $objLotto -> ID, $fp);
$strLo = "Lotto_".$_intLang;
$fp = str_replace("{ShowLotto}", $objLotto -> $strLo, $fp);

while(list($k, $v) = each($_strLotto)){
	$fp = str_replace("{".$k."}", $v, $fp);
}


preg_match("/<!-- @ ChRate Start @ \/\/-->(.+)<!-- @ ChRate End @ \/\/-->/s", $fp, $arrMatch);
$strChRateTmp = $arrMatch[1];

//兌換內容
$strCon = "";
foreach($arrBT as $intBT => $strBTName){

	$arrApointNumTip = $_arrGLineApointNumTip[$objLotto -> ID][$intBT];
	if(!is_array($arrApointNumTip))$arrApointNumTip = array("");

	foreach($arrApointNumTip as $intAN => $strApointTip){
		$strTmp = $strChRateTmp;
		$strTmp = str_replace("{ShowBTName}", $strBTName, $strTmp);
		$strTmp = str_replace("{ShowApoint}", $strApointTip, $strTmp);
		$strTmp = str_replace("{ShowAPN}", $intAN, $strTmp);
		$strTmp = str_replace("{ShowBT}", $intBT, $strTmp);
		$strTmp = str_replace("{ShowARate}", (float)$arrORate[$intBT][$intAN][11], $strTmp);
		$strTmp = str_replace("{ShowBRate}", (float)$arrORate[$intBT][$intAN][12], $strTmp);
		$strTmp = str_replace("{ShowCRate}", (float)$arrORate[$intBT][$intAN][13], $strTmp);
		$strTmp = str_replace("{ShowALineComm}", $arrBTComm[$intBT][1], $strTmp);
		$strTmp = str_replace("{ShowBLineComm}", $arrBTComm[$intBT][2], $strTmp);
		$strTmp = str_replace("{ShowCLineComm}", $arrBTComm[$intBT][3], $strTmp);
		$strCon .= $strTmp;
	}
}
$fp = preg_replace("/<!-- @ ChRate Start @ \/\/-->.+<!-- @ ChRate End @ \/\/-->/s", $strCon, $fp);

//輸出
WebOutputHTML($fp, 1);
?>